#include "CF_Includes.h"

CCF_TextureLoader::CCF_TextureLoader(void)
{
}

CCF_TextureLoader::~CCF_TextureLoader(void)
{
}

BOOL CCF_TextureLoader::FindImageFile( const LPWSTR filename, LPWSTR fullpath, DWORD nFullpathSize )
{
  WCHAR path[MAX_PATH];

  GetCurrentDirectory( MAX_PATH, path );

  if( SearchPath( path, filename, L".jpg", nFullpathSize, fullpath, NULL ) != 0 )
  {
    return TRUE;
  }
  else if( SearchPath( path, filename, L".tga", nFullpathSize, fullpath, NULL ) != 0 )
  {
    return TRUE;
  }

  return FALSE;
}

void CCF_TextureLoader::Initialize( LPDIRECT3DDEVICE9 device )
{
  this->m_device = device;
}

LPDIRECT3DTEXTURE9 CCF_TextureLoader::LoadFromFile( const LPWSTR filename )
{
  LPDIRECT3DTEXTURE9 result;
  WCHAR fullpath[ MAX_PATH ];

  FindImageFile( filename, fullpath, MAX_PATH );

  if( FAILED( D3DXCreateTextureFromFile( m_device, fullpath, &result )))
    return NULL;

  return result;
}